package com.lijiajia.cloud.authserver.service.impl.mongodb;

import com.lijiajia.cloud.authserver.pojo.mongodb.Client;
import com.lijiajia.cloud.authserver.pojo.mongodb.Role;
import com.lijiajia.cloud.authserver.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 角色服务 mongo实现
 *
 * @author lijiajia
 * @since 2019-4-28
 */
@Slf4j
@Service
public class MongoRoleService implements RoleService {

	private final MongoTemplate mongoTemplate;

	public MongoRoleService(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}


	@Override
	public List<Role> findByIds(Collection<String> ids) {
		Query query = Query.query(Criteria.where(Client.ID).in(ids));
		return mongoTemplate.find(query, Role.class);
	}

}
